package TUILayer;
import ControlLayer.*;
import java.util.*;

/**
 * Write a description of class LoanUI here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class LoanUI
{
    private LoanCtr loanCtr;
    
    public LoanUI()
    {
        loanCtr = new LoanCtr();
    }

    public void start()
    {        
        loanMenu();
    }
    
    public void loanMenu()
    {   
        boolean exit = false;
        while(!exit)
        {
            //show menu and return the user's choise
            int choise =   writeLoanMenu();
            if (choise == 1)
            {
                createLoan(); // Method that creates a loan by combining a Person and Specimen object. the loan is placed in a container.
            }
            else{if(choise == 2){
                   returnLoan(); // Method that removes a loan from the loanContainer. By giving the input of the returned DVD specimen.
                }
                else{
                    exit = true;
                } // end else
            }
        } // end while loop
    }
    
    private int writeLoanMenu()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\f *** DVD Menu ***");
        System.out.println(" (1) Create Loan");
        System.out.println(" (2) Return Loan");
        System.out.println(" (3) Return");
        System.out.print("\n Make your choise: ");
            
        int choise = keyboard.nextInt();
        return choise;
    }
    
    public int inputLoanerId()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);  
        System.out.println(" Write Id of loaner: ");
        int id = keyboard.nextInt();
        return id;
    }
    
    public int inputSpecimenKey()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);  
        System.out.println(" Write Serial Number of the wanted DVD specimen: ");
        int SpecimenKey = keyboard.nextInt();
        return SpecimenKey;
    }

    public int inputLoanId()
    {
        // creates an object keyboard to read data from the keyboard
         Scanner keyboard = new Scanner(System.in);  
         System.out.println("Write the ID of the loan: ");
         int loanId = keyboard.nextInt();
         return loanId;
    }

    public int inputDVDId()
    {
        // creates an object keyboard to read data from the keyboard
         Scanner keyboard = new Scanner(System.in);  
         System.out.println("Write the ID of the DVD: ");
         int dvdId = keyboard.nextInt();
         return dvdId;
    }
    
    public void createLoan()
    {
        int dvdId = inputDVDId();
        int loanerId = inputLoanerId();
        int specimenId = inputSpecimenKey();
        int loanId = inputLoanId();
        loanCtr.createLoan(dvdId, loanerId, specimenId, loanId);
    }
    
    public void returnLoan()
    {
        int loanId = inputLoanId();
        loanCtr.returnLoan(loanId);
    }
}